import table from '@/components/dt/table/render.js'
import Opt from '@/components/dt/info/Opt.js'
import dt from '@dt/dt'
let _this = null
let tabVal = 1
class Column extends Opt {
  constructor(vm, val) {
    super()
    _this = vm
    tabVal = val
    this.build()
  }

  build() {
    this.createAll()
    this.opts.push(...this.all)
  }

  createAll() {
    if (tabVal == 1) {
      this.all = [
        {
          field: 'thumbnailPicUrl',
          title: '模板预览',
          minWidth: 150,
          slots: {
            default: (params, h) => {
              let img = {
                event: 'seeBg',
                src: params.row.thumbnailPicUrl ? params.row.thumbnailPicUrl : '',
                data: params.row.previewUrl
              }
              return params.row.thumbnailPicUrl ? table.cell.img(_this, h, img, false) : '-'
            }
          }
        },
        {
          field: 'templateName',
          title: '模板名称',
          minWidth: 100
        },
        {
          field: 'templateType',
          title: '模板类型',
          minWidth: 100,
          slots: {
            default: (params, h) => {
              return dt.dictInfo().__value('templateType', params.row.templateType)
            }
          }
        },
        {
          field: 'quoteCount',
          title: '引用人次',
          minWidth: 150
        },
        {
          field: 'userName',
          title: '操作人',
          minWidth: 180,
          slots: {
            default: (params, h) => {
              return params.row.userName + '(' + params.row.workNo + ')'
            }
          }
        },
        {
          field: 'updateTime',
          title: '操作时间',
          minWidth: 180
        },

        {
          field: 'handles',
          title: '操作',
          minWidth: 150,
          fixed: 'right',

          slots: {
            default: (params, h) => {
              let btns = []
              let item = params.row
              btns.push({
                title: '下架',
                event: 'offShelf',
                data: item
              })
              if (item.top == 0) {
                btns.push({
                  title: '置顶',
                  event: 'pinned',
                  data: item
                })
              } else {
                btns.push({
                  title: '取消置顶',
                  event: 'unpinned',
                  data: item
                })
              }
              return table.cell.btns(_this, h, btns)
            }
          }
        }
      ]
    } else {
      this.all = [
        {
          field: 'thumbnailPicUrl',
          title: '模板预览',
          minWidth: 150,
          slots: {
            default: (params, h) => {
              let img = {
                event: 'seeBg',
                src: params.row.thumbnailPicUrl ? params.row.thumbnailPicUrl : '',
                data: params.row.previewUrl
              }
              return params.row.thumbnailPicUrl ? table.cell.img(_this, h, img, false) : '-'
            }
          }
        },
        {
          field: 'templateName',
          title: '模板名称',
          minWidth: 100,
          header: {
            filter: {
              title: '模板名称',
              key: 'templateName',
              placeholder: '请选择',
              input: {}
            }
          }
        },
        {
          field: 'templateType',
          title: '模板类型',
          minWidth: 100,
          header: {
            filter: {
              title: '模板类型',
              key: 'templateType',
              placeholder: '请选择',
              select: {
                options: dt.dictInfo().templateType
                // multiple: true,
                // filterable: true
              }
            }
          },
          slots: {
            default: (params, h) => {
              return dt.dictInfo().__value('templateType', params.row.templateType)
            }
          }
        },
        {
          field: 'quoteCount',
          title: '引用人次',
          minWidth: 150,
          remoteSort: true,
          sort: {
            key: 'quoteCountSort',
            desc: '2',
            asc: '1'
          }
        },
        {
          field: 'userName',
          title: '操作人',
          minWidth: 80,
          slots: {
            default: (params, h) => {
              return params.row.userName + '(' + params.row.workNo + ')'
            }
          }
        },
        {
          field: 'updateTime',
          title: '操作时间',
          minWidth: 180
        },

        {
          field: 'handles',
          title: '操作',
          minWidth: 150,
          fixed: 'right',

          slots: {
            default: (params, h) => {
              let btns = []
              let item = params.row
              btns.push({
                title: '上架',
                event: 'upShelf',
                data: item
              })
              btns.push({
                title: '编辑',
                event: 'bgEdit',
                data: item
              })
              return table.cell.btns(_this, h, btns)
            }
          }
        }
      ]
    }
  }
}

export default Column
